<?php
/**
 * Created by PhpStorm.
 * User: 35083
 * Date: 2019/6/26
 * Time: 17:50
 */

/**
 * 设置缓存
 * @param $key 键
 * @param $value 值
 * @param int $expire 过期时间 秒
 */
function setCache($key, $value, $expire = 0)
{
    $config = config("cache.default");
    if ($expire) {
        $config['expire'] = $expire;
    }
    $cache = cache($config); //定义
    $cache->set($key, $value);
}

/**
 * 获取缓存
 * @param $key 键
 * @return mixed
 */
function getCache($key)
{
    $config = config("cache.default");
    $cache = cache($config); //定义
    return $cache->get($key);
}

function setRedisCache($key, $val)
{
    \think\Cache::store('redis')->set($key, $val);

}

function getRedisCache($key)
{
    return \think\Cache::store('redis')->get($key);
}

function setFileCache($key, $val, $expire = 0)
{
    \think\Cache::store('file')->set($key, $val, $expire);

}

function getFileCache($key)
{
    return \think\Cache::store('file')->get($key);
}
